package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.injector.methods.SelectList;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.pojo.Employee;
import com.itheima.dao.EmployeeMapper;
import com.itheima.pojo.Pageparam;
import com.itheima.service.IEmployeeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;

import java.util.List;

/**
 * <p>
 * 员工信息 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-11-28
 */
@Service
@Transactional
@Slf4j
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper dao;
    long id=Thread.currentThread().getId();
    @Override
    public Employee findEmployee(String username) {
        log.info("业务层线程id为 {}",id);
        LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Employee::getUsername, username);
        Employee employee = dao.selectOne(lqw);
        return employee;
    }

    @Override
    public int addEmp(Employee employee) {

        return   dao.insert(employee);
    }

    @Override
    public int updateEmp(Employee employee) {
        return   dao.updateById(employee);
    }
    @Override
    public Page initPage(Pageparam pageparam) {
        Page page = new Page(pageparam.getPage(), pageparam.getPageSize());
        LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(pageparam.getName()!=null,Employee::getName, pageparam.getName());
        Page page1 = dao.selectPage(page, queryWrapper);
        return page1;

    }}
